# Maintainer: Tim Meusel <tim@bastelfreak.de>
# Contributor: Anatoly Bashmakov <anatoly at posteo dot net>

_gemname='ruby2_keywords'
pkgname="ruby-${_gemname}"
pkgver=0.0.5
pkgrel=1
pkgdesc='Shim library for Module#ruby2_keywords'
arch=('any')
url="https://github.com/ruby/${_gemname}"
license=('RUBY' 'BSD')
depends=('ruby')
makedepends=('ruby-rdoc' 'ruby-rake' 'ruby-bundler')
checkdepends=('ruby-test-unit')
options=('!emptydirs')
source=("${url}/archive/v${pkgver}/${_gemname}-v${pkgver}.tar.gz")
sha512sums=('5d8df98fe65ac70b850eeff8577311d93af7b0a85fe1d97c0a1079ff65e4509d1dc4173b947245eeac90c2a0ff4d4a2debba749f8965ffcb1f5b72e175a90a3e')

prepare() {
  cd "${srcdir}/${_gemname}-${pkgver}"
  # since 0.0.5 release the changelog isn't presend as a markdown file
  # but as a broken rake task that we need to disable
  # https://github.com/ruby/ruby2_keywords/issues/17
  sed --in-place '/ChangeLog/d' "${_gemname}.gemspec"
  rm rakelib/changelogs.rake
}

build() {
  cd "${srcdir}/${_gemname}-${pkgver}"
  gem build "${_gemname}.gemspec"
}

check() {
  cd "${srcdir}/${_gemname}-${pkgver}"
  rake test
}

package() {
cd "${srcdir}/${_gemname}-${pkgver}"
  local _gemdir="$(gem env gemdir)"
  gem install --verbose --ignore-dependencies --no-user-install --install-dir "${pkgdir}/${_gemdir}" --bindir "${pkgdir}/usr/bin" "${_gemname}-${pkgver}.gem"

  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}/"

  install -Dm 644 README.md -t "${pkgdir}/usr/share/doc/${pkgname}"

  rm -rf "${pkgdir}/${_gemdir}/cache"
}
